/**   
* @Title: RespCode.java 
* @Package cn.com.geasy.core.exception 
* @Description: TODO(描述该文件做什么)
* @author xucan   
* @date 2016年11月2日 下午11:12:56 
*/
package com.workManager.config;



import org.apache.commons.lang3.StringUtils;


import java.io.Serializable;

/** 
* @ClassName: RespCode 
* @Description: 全局响应编码
* @author xucan
* @date 2016年11月2日 下午11:12:56 
*  
*/
@SuppressWarnings("serial")
public class RespCode implements Serializable {
	/** 200请求成功 */
	public final static RespCode OK = new RespCode(200);
	/** 身份未认证 */
	public final static RespCode ACCOUNT_PASSWORD_ERROR = new RespCode(30000);
	/** 身份未认证 */
	public final static RespCode UNAUTHORIZED = new RespCode(30001);
	/** 未登录 */
	public final static RespCode LOGIN_FAIL = new RespCode(30002);
	/** 权限不足 */
	public final static RespCode FORBIDDEN = new RespCode(30003);
	/**旧密码不正确*/
	public final static RespCode OLDPASSWORD_NULL = new RespCode(30005);
	/** 频繁操作 */
	public final static RespCode MULTI_STATUS = new RespCode(30004);
	/** 参数不能为空 */
	public final static RespCode PARAM_NOT_NULL = new RespCode(30010);
	/** 参数格式不正确 */
	public final static RespCode PARAM_NOT_FORMAT = new RespCode(30011);
	/** 非法参数 */
	public final static RespCode PARAM_ILLEGAL = new RespCode(30012);
	/** 数据解析有误 */
	public final static RespCode DATA_PARSE = new RespCode(30013);
	/** 参数值太小 */
	public final static RespCode PARAM_MIN_VALUE = new RespCode(30014);
	/** 参数值太大 */
	public final static RespCode PARAM_MAX_VALUE = new RespCode(30015);
	/** 参数长度过少 */
	public final static RespCode PARAM_MIN_LENGTH = new RespCode(30016);
	/** 参数长度过长 */
	public final static RespCode PARAM_MAX_LENGTH = new RespCode(30017);
	/** 无效用户 */
	public final static RespCode USER_INVALID = new RespCode(30020);
	/** 用户状态错误 */
	public final static RespCode USER_LOCKED = new RespCode(30021);
	/** 500服务器出错 */
	public final static RespCode INTERNAL_SERVER_ERROR = new RespCode(500);
	/** 自定义错误编码 */
	public final static RespCode DEFINE_ERROR = new RespCode(500);
	/** 没有客服 */
	public final static RespCode NON_KFUSER = new RespCode(60001);

	private Integer value;
	
	private String msg;
	
	private Object[] valueObject = null;

	private RespCode(Integer value) {
		this.value = value;
	}
	
	private RespCode() {
	}
	
	private RespCode(Integer value, String msg) {
		this.value = value;
		this.msg = msg;
	}
	
	public static RespCode paramFormat(RespCode respCode, Object... objects){
		respCode = new RespCode(respCode.value, respCode.msg);
		respCode.valueObject = objects;
		return respCode;
	}
	
	public static RespCode defineRespCode(Integer code, String msg){
		RespCode respCode = new RespCode(code, msg);
		return respCode;
	}
	
	public static RespCode defineRespCode(RespCode respCode, String msg){
		respCode = new RespCode(respCode.value, msg);
		return respCode;
	}
	
	public static RespCode defineRespCode(String msg){
		RespCode respCode = new RespCode(500, msg);
		respCode.msg = msg;
		return respCode;
	}

	public Integer value() {
		return this.value;
	}

	public String msg() {
		if(StringUtils.isNotBlank(msg)){
			return msg;
		}
		return Resources.getMessage("CODE_" + this.value, valueObject);
	}
	
	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String toString() {
		return this.value.toString();
	}
}
